/* eslint-disable */
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import $ from 'jquery'
import echarts from 'echarts'
import store from './store'
import common from './assets/js/common'
import axios from 'axios'
import '@/common/elementUi/js/components'
import moment from 'moment'
// import fastClick from 'fastclick'
import VueLodash from 'vue-lodash'

import './assets/styles/reset.css'
import './assets/styles/border.css'
import './assets/styles/iconfont.css'
import './assets/styles/presetFont.css'
import './assets/styles/theme.styl'
import './assets/styles/common.styl'
// import animate from 'animate.css'

Vue.config.productionTip = false
Vue.prototype.$echarts = echarts
Vue.prototype.$common = common
Vue.prototype.$http = axios
Vue.prototype.$moment = moment
window.jQuery = $
window.$ = $
// Vue.use(animate)
// fastClick.attach(document.body)
Vue.use(VueLodash)


// 空状态
Vue.component("NoData", {
    template:`
      <div class="noData" :class="bg ? 'bg' : ''">
        <img src="./static/images/noData.png" />
        <p>暂无{{item}}记录</p>
      </div>
    `,
    props: {
      'item': {
        type: String,
        default: ''
      },
      'bg': {
        type: Boolean,
        default: false
      }
    }
})

router.beforeEach((to, _, next) => {
  const requireAuth = to.matched.some(m => m.meta.requireAuth)
  const level = to.matched.map(m => m.meta.level).filter(l => !!l)[0]
  // 判断该路由是否需要登录权限
  if (requireAuth) {
    if (store.getters.isLogin) {
      if (level) {
        const { isGardenLevel } = store.getters
        if (level === 'garden' && !isGardenLevel) {
          next({ path: to.path.replace('/garden', '') })
        } else if (level === 'home' && isGardenLevel) {
          next({ path: `/garden${to.path}` })
        } else {
          next()
        }
      } else {
        next()
      }
    } else {
      next({
        path: '/login',
        query: {redirect: to.fullPath}
      })
    }
  } else {
    next()
  }
})

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
